'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 4_handle_callback_with_roolback.py
* @Time: 2025/10/29
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
dotenv.load_dotenv()
@tool
def complex_tool(int_arg:int, float_arg:float)->int:
    """使用复杂工具进行计算操作"""
    return int(int_arg * float_arg)


#1、创建大模型并绑定工具
llm = ChatOpenAI(model = "gpt-4o-mini000", temperature=0).bind_tools([complex_tool])
better_llm = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind_tools([complex_tool])

#2、创建链并执行工具
better_chain = better_llm|(lambda msg:msg.tool_calls[0]["args"])|complex_tool
chain = (llm|(lambda msg:msg.tool_calls[0]["args"])|complex_tool).with_fallbacks([better_chain])
#3、调用链
print(chain.invoke("使用复杂工具,对应参数为 5 和 2.1"))
